#ifndef _MOE_REAL_SINGLE_POINT_CROSSOVER
#define _MOE_REAL_SINGLE_POINT_CROSSOVER

#include <iostream>

using namespace std;

#include "engine/Random.hh"
#include "problems/RealArraySolution.hh"
#include "engine/Crossover.hh"

class RealSinglePointCrossover: public Crossover {

public:

    RealSinglePointCrossover() : Crossover() {}

    virtual ~RealSinglePointCrossover() {}

    int matesExpected() {
        return 2;
    }


protected:

    ArrayList<Solution> *cross(ArrayList<Solution> *mates) {
        if (mates->length() != 2) {
            cout << "mates must be two, in single point crossover" << endl;
            exit(1);
        }

        RealArraySolution *solution0 = (RealArraySolution*)mates->get(0);
        RealArraySolution *solution1 = (RealArraySolution*)mates->get(1);

        RealArraySolution *child0 = new RealArraySolution();
        RealArraySolution *child1 = new RealArraySolution();


        int size = RealArraySolution::getSize();
        int r = Random::getInstance()->getInt(size);

        for (int i = 0; i < size; i++) {
            if (i < r) {

                child0->set(i, solution0->get(i));
                child1->set(i, solution1->get(i));

            } else {

                child0->set(i, solution1->get(i));
                child1->set(i, solution0->get(i));

            }

        }


        ArrayList<Solution> *childs = new ArrayList<Solution>(false);
        childs->add(child0);
        childs->add(child1);

        return childs;
    }
};


#endif
